#include "TableSymb.hpp"

TableSymb::TableSymb()
{
}

void TableSymb::add(const unsigned int id, const Symbole* symb)
{
	if(get(id) == NULL) {
		symboles.insert(std::make_pair(id, (Symbole *)symb));
	}
}


Symbole* TableSymb::get(const unsigned int id) const
{
	map<const unsigned int, Symbole*>::const_iterator it;
	it = symboles.find(id);

	if(it == symboles.end()) {
		return NULL;
	}
	return it->second;
}

void TableSymb::print() const
{
	map<const unsigned int, Symbole*>::const_iterator itr;
	for(itr = symboles.begin(); itr != symboles.end(); ++itr){
	    	cout << "Key: " << itr->first << " Value: "
				<< itr->second->getCategory() << ", "
				<< itr->second->toString() << endl;
		/*
	  	Cste *symbCste = dynamic_cast<Cste *>((itr->second));
	   	if(symbCste == NULL) {
	    	cout << "Key: " << itr->first << " Value: "
				<< *(itr->second) << endl;
	    }else{
	     	cout << "Cst" << (symbCste->toString()) << endl;
	    }
		*/
	}
}

TableSymb::~TableSymb() {

	/*map<int, Symbole*>::const_iterator itr;
	for(itr = symboles.begin(); itr != symboles.end(); ++itr){
		Symbole* Value = (*itr).second;
		delete Value;
	}
	itr.clear();*/
}

